/**
 *       \file  py_reservoir_simulator.h
 *      \brief  Exports python wrappers for reservoir_simulator,
 *              see reservoir_simulator.h
 *     \author  Sergey Miryanov (sergey-miryanov), sergey.miryanov@gmail.com
 *       \date  18.07.2008
 *  \copyright  This source code is released under the terms of 
 *              the BSD License. See LICENSE for more details.
 * */
#ifndef PY_RESERVOIR_SIMULATOR_H
#define PY_RESERVOIR_SIMULATOR_H

#ifdef BSPY_EXPORTING_PLUGIN
#include "py_event_manager.h"
#include "py_calc_model.h"

#include BS_FORCE_PLUGIN_IMPORT ()
#include "py_data_manager.h"
#include "py_jacobian_matrix.h"
#include "py_linear_solvers.h"
#include BS_STOP_PLUGIN_IMPORT ()

namespace blue_sky {
namespace python {


	 template <typename T>
  typename T::sp_jmatrix_t 
  get_jmatrix (T *t)
  {
    return t->jacobian_->get_jmatrix ();
  }

  template <typename T>
  typename T::reservoir_t::sp_facility_manager_t
  get_facility_list (T *t)
  {
    return t->reservoir_->get_facility_list ();
  }

  template <typename T>
  bool
  subscribe (T *t, int signal_code, const python_slot &slot)
  {
    bool result = t->subscribe (signal_code, slot.spslot);
    result &=     t->subscribe (objbase::on_delete, new blue_sky::tools::py_object_handler (boost::python::detail::wrapper_base_::get_owner (slot)));

    return result;
  }

  PY_EXPORTER (reservoir_simulator_exporter, default_exporter)
    .def ("init",                     &T::read_keyword_file_and_init)
    .def ("simulate",                 &T::main_loop)
    .def ("simulate",                 &T::simulate)
    .def ("subscribe",                subscribe <T>)
    .add_property ("facility_list",   make_function (get_facility_list <T>))
    .add_property ("jmatrix",         make_function (get_jmatrix <T>))
	.add_property ("calc_model",  make_getter (&T::cm, return_value_policy <copy_non_const_reference> ()))
    .add_property ("reservoir",       make_getter (&T::reservoir_, return_value_policy <copy_non_const_reference> ()))
    .add_property ("mesh",            make_getter (&T::mesh, return_value_policy <copy_non_const_reference> ()))
    .add_property ("event_manager",   make_getter (&T::em, return_value_policy <copy_non_const_reference> ()))
    .add_property ("data_manager",    make_getter (&T::dm, return_value_policy <copy_non_const_reference> ()))
    .add_property ("jacobian",        make_getter (&T::jacobian_, return_value_policy <copy_non_const_reference> ()))
    .add_property ("keyword_manager", make_getter (&T::keyword_manager_, return_value_policy <copy_non_const_reference> ()))
  PY_EXPORTER_END;

  /**
   * \brief  Exports wrappers to python
   * */
  void 
  py_export_reservoir_simulator ();

} // namespace python
} // namespace blue_sky

#endif
#endif // PY_RESERVOIR_SIMULATOR_H
